//
//  ASTabBarViewController.swift
//  weiboBlog
//
//  Created by asenter on 16/3/26.
//  Copyright © 2016年 asenter. All rights reserved.
//

import UIKit

class ASTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        addChildController()
        
        self.setValue(ASTabbar(), forKey: "tabBar")
    }
    
    func addChildController(){
        
        //添加首页按钮
        let homeVC = HomeViewController()
        addChildViewController(homeVC, title: "首页", imageName: "tabbar_home")
        
        //添加发现按钮
        let discoverVC = DiscoverViewController()
        addChildViewController(discoverVC, title: "发现", imageName: "tabbar_discover")
        
        //添加消息按钮
        let messageVC = MessageViewController()
        addChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        //添加我的中心按钮
        let profileVC = ProfileViewController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile")
    }
    
    //按钮添加方法
    func addChildViewController(controller: UIViewController,title: String,imageName: String) {
        
        controller.title = title;
        
        controller.tabBarItem.image = UIImage(named: imageName)
        
        let heightedImageName = imageName + "_heighted"
        
        controller.tabBarItem.selectedImage = UIImage(named: heightedImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName :UIColor.orangeColor()], forState: UIControlState.Selected)
        
        addChildViewController(UINavigationController(rootViewController: controller))
    }
    

    

}
